#include <QApplication>
#include "mainmenu.h"

//连接主菜单和主窗口界面
void connectMainMenuAndMainWidget(MainMenu& mainMenu){
    QObject::connect(mainMenu.mainWidget, Widget::showMainMenu, &mainMenu, MainMenu::showMainMenu);
//    QObject::connect(&mainMenu, MainMenu::sendShowMainWidget, mainMenu.mainWidget, Widget::showWidget);
//    QObject::connect(&mainMenu, MainMenu::sendMoShi, mainMenu.mainWidget, Widget::recMoShi);
}

//连接主菜单和结束游戏界面
void connectMainMenuAndEndGameDialog(MainMenu& mainMenu){
    QObject::connect(mainMenu.mainWidget->egd, EndGameDialog::showMainMenu, &mainMenu, MainMenu::showMainMenu);
}

//连接主窗口和结束游戏界面
void connectMainWidgetAndEndGameDialog(MainMenu& mainMenu){
    QObject::connect(mainMenu.mainWidget->egd, EndGameDialog::closeMainWidget, mainMenu.mainWidget, Widget::closeWidget);
    QObject::connect(mainMenu.mainWidget->egd, EndGameDialog::showMainWidget, mainMenu.mainWidget, Widget::showWidget);
    QObject::connect(mainMenu.mainWidget->egd, EndGameDialog::endMusic, mainMenu.mainWidget, Widget::endMusic);
    QObject::connect(mainMenu.mainWidget->egd, EndGameDialog::endGame, mainMenu.mainWidget, Widget::endGame);
//    QObject::connect(mainMenu.mainWidget->egd, EndGameDialog::sendSaveScore, mainMenu.mainWidget, Widget::recSaveScore);
//    QObject::connect(mainMenu.mainWidget, Widget::sendShowEGD, mainMenu.mainWidget->egd, EndGameDialog::recShowEGD);
//    QObject::connect(mainMenu.mainWidget, Widget::sendModeToEGD, mainMenu.mainWidget->egd, EndGameDialog::recModeToEGD);
}

//连接主窗口和关卡选择界面
void connectMainWidgetAndGuanQiaChoose(MainMenu& mainMenu){
//    QObject::connect(mainMenu.gqc, guanQiaChoose::sendMoShi, mainMenu.mainWidget, Widget::recMoShi);
//    QObject::connect(mainMenu.gqc, guanQiaChoose::sendMoShi, mainMenu.mainWidget, Widget::recMoShi);
    QObject::connect(&mainMenu, MainMenu::sendMoShi, mainMenu.mainWidget, Widget::recMoShi);

//    void(guanQiaChoose::*send)(int) =&guanQiaChoose::sendGuanQia;
//    void(Widget::*rec)(int)=&Widget::recGuanQia;
//    QObject::connect(mainMenu.gqc, send, mainMenu.mainWidget, rec);

//    QObject::connect(mainMenu.gqc, guanQiaChoose::sendClearScoreInWidget, mainMenu.mainWidget, Widget::recClearScoreInWidget);
//    QObject::connect(mainMenu.gqc, guanQiaChoose::sendShowMainWidget, mainMenu.mainWidget, Widget::showWidget);
//    QObject::connect(mainMenu.mainWidget, Widget::sendShowEGD, mainMenu.mainWidget->egd, EndGameDialog::recShowEGD);
}

//连接主菜单和关卡选择界面
void connectMainMenuAndGuanQiaChoose(MainMenu& mainMenu){
    void(MainMenu::*send)(int) =&MainMenu::sendScore;
    void(guanQiaChoose::*rec)(int)=&guanQiaChoose::recScore;
    QObject::connect(&mainMenu, send, mainMenu.gqc, rec);

//    void(MainMenu::*send2)(int) =&MainMenu::sendFlag2;
//    void(guanQiaChoose::*rec2)(int)=&guanQiaChoose::recFlag2;
//    QObject::connect(&mainMenu, send2, mainMenu.gqc, rec2);

//    QObject::connect(&mainMenu, mainMenu.sendShowGQC, mainMenu.gqc, guanQiaChoose::recShowGQC);
}

//连接主窗口和我界面
void connectMainWidgetAndMe(MainMenu& mainMenu){
    QObject::connect(mainMenu.mainWidget, Widget::showMe, mainMenu.mainWidget->me, Me::showMe);
    QObject::connect(mainMenu.mainWidget->me, Me::showWidget, mainMenu.mainWidget, Widget::showWidget);
    QObject::connect(mainMenu.mainWidget, Widget::sendChangeScoreInMeUi, mainMenu.mainWidget->me, Me::recChangeScoreInMeUi);
    QObject::connect(mainMenu.mainWidget->me, Me::sendChangeScoreInMainWidget, mainMenu.mainWidget, Widget::recChangeScoreInMainWidget);
}

//连接登录和我界面
void connectLoginAndMe(MainMenu& mainMenu){
    QObject::connect(mainMenu.mainWidget->me, Me::showLogin, mainMenu.mainWidget->me->login, Login::showLogin);
    QObject::connect(mainMenu.mainWidget->me->login, Login::showMe, mainMenu.mainWidget->me, Me::showMe);

    void(Login::*send)(User*) =&Login::sendLoginUser;
    void(Me::*rec)(User *)=&Me::recLoginUser;
    QObject::connect(mainMenu.mainWidget->me->login, send, mainMenu.mainWidget->me, rec);
}

//连接注册和我界面
void connectRegistAndMe(MainMenu& mainMenu){
    QObject::connect(mainMenu.mainWidget->me->regist, Regist::showMe, mainMenu.mainWidget->me, Me::showMe);

    void(Regist::*send2)(User*) =&Regist::sendRegistUser;
    void(Me::*rec2)(User *)=&Me::recRegistUser;
    QObject::connect(mainMenu.mainWidget->me->regist, send2, mainMenu.mainWidget->me, rec2);

    QObject::connect(mainMenu.mainWidget->me, Me::showRegist, mainMenu.mainWidget->me->regist, Regist::showRegist);
}

//连接排行榜和我界面
void connectPaiHangAndMe(MainMenu& mainMenu){
    QObject::connect(mainMenu.mainWidget->me, Me::sendZhiZuoPaiHang, mainMenu.mainWidget->me->paihang, PaiHang::recZhiZuoPaiHang);
    QObject::connect(mainMenu.mainWidget->me->paihang, PaiHang::showMe, mainMenu.mainWidget->me, Me::showMe);
}

////连接toChatRoom和我界面
//void connectToChatRoomAndMe(MainMenu& mainMenu){
//    QObject::connect(mainMenu.mainWidget->me, Me::showToChatRoom, mainMenu.mainWidget->me->toChatRoom, ToChatRoom::recShowToChatRoom);
//    QObject::connect(mainMenu.mainWidget->me->toChatRoom, ToChatRoom::sendShowMe, mainMenu.mainWidget->me, Me::showMe);
//    QObject::connect(mainMenu.mainWidget->me->toChatRoom, ToChatRoom::sendClearNewMessage, mainMenu.mainWidget->me, Me::recClearNewMessage);
//}

////连接我的好友和toChatRoom界面
//void connectMyFriendAndToChatRoom(MainMenu& mainMenu){
//    QObject::connect(mainMenu.mainWidget->me->toChatRoom, ToChatRoom::sendShowMyFriend, mainMenu.mainWidget->me->toChatRoom->myFriend, MyFriend::recShowMyFriend);
//    QObject::connect(mainMenu.mainWidget->me->toChatRoom->myFriend, MyFriend::sendShowToChatRoom, mainMenu.mainWidget->me->toChatRoom, ToChatRoom::recShowToChatRoom);
//    QObject::connect(mainMenu.mainWidget->me->toChatRoom->myFriend, MyFriend::sendChooseFriendToToChatRoom, mainMenu.mainWidget->me->toChatRoom, ToChatRoom::recChooseFriendToToChatRoom);
//}

////连接toChatRoom和聊天室界面
//void connectToChatRoomAndChatRoom(MainMenu& mainMenu){
//    QObject::connect(mainMenu.mainWidget->me->toChatRoom, ToChatRoom::sendShowChatRoom, mainMenu.mainWidget->me->toChatRoom->charRoom, ChatRoom::recShowChatRoom);
//    QObject::connect(mainMenu.mainWidget->me->toChatRoom->charRoom, ChatRoom::sendBackClicked, mainMenu.mainWidget->me->toChatRoom, ToChatRoom::recBackClicked);
//}

////连接聊天室和我界面
//void connectChatRoomAndMe(MainMenu& mainMenu){
//    QObject::connect(mainMenu.mainWidget->me->toChatRoom->charRoom, ChatRoom::sendShowMe, mainMenu.mainWidget->me, Me::showMe);
//    QObject::connect(mainMenu.mainWidget->me->toChatRoom->charRoom, ChatRoom::sendNewMessageToMe, mainMenu.mainWidget->me, Me::recNewMessageToMe);
//    QObject::connect(mainMenu.mainWidget->me->toChatRoom->charRoom, ChatRoom::sendClearNewMessage, mainMenu.mainWidget->me, Me::recClearNewMessage);
//    QObject::connect(mainMenu.mainWidget->me, Me::showChatRoom, mainMenu.mainWidget->me->toChatRoom->charRoom, ChatRoom::recShowChatRoom);
//}


//连接历史记录和我界面
void connectHistoryAndMe(MainMenu& mainMenu){
    QObject::connect(mainMenu.mainWidget->me, Me::sendShowHistory, mainMenu.mainWidget->me->history, History::recShowHistory);
    QObject::connect(mainMenu.mainWidget->me->history, History::showMe, mainMenu.mainWidget->me, Me::showMe);

    void(Me::*send3)(QString) =&Me::sendUpdateHistory;
    void(History::*rec3)(QString)=&History::recUpdateHistory;
    QObject::connect(mainMenu.mainWidget->me, send3, mainMenu.mainWidget->me->history,rec3);

    void(Me::*send4)(QString, QString) =&Me::sendNameToHistory;
    void(History::*rec4)(QString, QString)=&History::recNameToHistory;
    QObject::connect(mainMenu.mainWidget->me, send4, mainMenu.mainWidget->me->history, rec4);
}

//连接历史记录和确认清空界面
void connectHistoryAndSureClear(MainMenu& mainMenu){
    QObject::connect(mainMenu.mainWidget->me->history->sureClear, SureClear::sendYesClear, mainMenu.mainWidget->me->history, History::recYesClear);
    QObject::connect(mainMenu.mainWidget->me->history->sureClear, SureClear::sendNoClear, mainMenu.mainWidget->me->history, History::recNoClear);
    QObject::connect(mainMenu.mainWidget->me->history, History::sendShowSureClear, mainMenu.mainWidget->me->history->sureClear, SureClear::recShowSureClear);
}

////连接添加好友和我的好友界面
//void connectAddFriendAndMyFriend(MainMenu& mainMenu){
//    QObject::connect(mainMenu.mainWidget->me->toChatRoom->myFriend, MyFriend::sendShowAddFriend, mainMenu.mainWidget->me->toChatRoom->myFriend->addFriend, AddFriend::recShowAddFriend);
//    QObject::connect(mainMenu.mainWidget->me->toChatRoom->myFriend->addFriend, AddFriend::sendShowMyFriend, mainMenu.mainWidget->me->toChatRoom->myFriend, MyFriend::recShowMyFriend);
//    QObject::connect(mainMenu.mainWidget->me->toChatRoom->myFriend->addFriend, AddFriend::sendNewFriendToMyFriend, mainMenu.mainWidget->me->toChatRoom->myFriend, MyFriend::recNewFriendToMyFriend);
//}

//连接修改密码和我界面
void connectChangePwdAndMe(MainMenu& mainMenu){
    QObject::connect(mainMenu.mainWidget->me->changePwd, ChangePwd::sendShowMe, mainMenu.mainWidget->me, Me::showMe);
    QObject::connect(mainMenu.mainWidget->me, Me::sendShowChangePwd, mainMenu.mainWidget->me->changePwd, ChangePwd::recShowChangePwd);

    void(ChangePwd::*send)(QString) =&ChangePwd::sendNewPwdToMe;
    void(Me::*rec)(QString)=&Me::recNewPwdToMe;
    QObject::connect(mainMenu.mainWidget->me->changePwd, send, mainMenu.mainWidget->me, rec);
}

//连接确认注销账号和我界面
void connectSureDelAccountAndMe(MainMenu& mainMenu){
    QObject::connect(mainMenu.mainWidget->me, Me::sendShowSureDelAccount, mainMenu.mainWidget->me->sureDelAccount, SureDelAccount::recShowSureDelAccount);
    QObject::connect(mainMenu.mainWidget->me->sureDelAccount, SureDelAccount::sendSureDelAccountToMe, mainMenu.mainWidget->me, Me::recSureDelAccountToMe);
}

//连接修改昵称和我界面
void connectChangeNickNameAndMe(MainMenu& mainMenu){
    QObject::connect(mainMenu.mainWidget->me, Me::sendShowChangeNickName, mainMenu.mainWidget->me->changeNickName, ChangeNickName::recShowChangeNickName);
    QObject::connect(mainMenu.mainWidget->me->changeNickName, ChangeNickName::sendShowMe, mainMenu.mainWidget->me, Me::showMe);
    QObject::connect(mainMenu.mainWidget->me->changeNickName, ChangeNickName::sendNewNickNameToMe, mainMenu.mainWidget->me, Me::recNewNickNameToMe);
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    MainMenu mainMenu;

    connectMainMenuAndMainWidget(mainMenu); //连接主菜单和主窗口界面
    connectMainMenuAndEndGameDialog(mainMenu); //连接主菜单和结束游戏界面
    connectMainWidgetAndEndGameDialog(mainMenu); //连接主窗口和结束游戏界面
    connectMainWidgetAndMe(mainMenu); //连接主窗口和我界面
//    connectMainWidgetAndGuanQiaChoose(mainMenu); //连接主窗口和关卡选择界面
//    connectMainMenuAndGuanQiaChoose(mainMenu); //连接主菜单和关卡选择界面
    connectLoginAndMe(mainMenu); //连接登录和我界面
    connectRegistAndMe(mainMenu); //连接注册和我界面
    connectPaiHangAndMe(mainMenu); //连接排行榜和我界面
//    connectToChatRoomAndMe(mainMenu); //连接toChatRoom和我界面
//    connectToChatRoomAndChatRoom(mainMenu); //连接toChatRoom和聊天室界面
//    connectChatRoomAndMe(mainMenu); //连接聊天室和我界面
    connectHistoryAndMe(mainMenu); //连接历史记录和我界面
    connectHistoryAndSureClear(mainMenu); //连接历史记录和确认清空界面
//    connectMyFriendAndToChatRoom(mainMenu); //连接我的好友和toChatRoom界面
//    connectAddFriendAndMyFriend(mainMenu); //连接添加好友和我的好友界面
    connectChangePwdAndMe(mainMenu); //连接修改密码和我界面
    connectChangeNickNameAndMe(mainMenu); //连接修改昵称和我界面
    connectSureDelAccountAndMe(mainMenu); //连接确认注销账号和我界面


    mainMenu.show();

    return a.exec();
}
